package designmodel.strategy.收银策略练习.strategies;

import designmodel.strategy.收银策略练习.CashStrategy;

import java.text.MessageFormat;

/**
 * 按照折扣率: discountPercent 打折
 *
 * @author scylla
 * @version V1.0
 * @project echo -java-base
 * @title 打折策略
 * @package designmodel.strategy.收银策略练习.strategies
 * @since 2021 /12/16 5:08 下午
 */
public class DiscountStrategy implements CashStrategy {

    //折率
    private double discountPercent;

    /**
     * Instantiates a new Discount strategy.
     */
    public DiscountStrategy() {
    }

    @Override
    public double pay(double cash) {
        System.out.println("====折扣====");
        System.out.println(MessageFormat.format("收银{0}元，折扣率:{1}", cash, discountPercent));
        return cash * discountPercent;
    }


    /**
     * The type Builder.
     */
    public static class Builder {

        private DiscountStrategy discountStrategy;

        //折率
        private double discountPercent;

        /**
         * Instantiates a new Builder.
         */
        public Builder() {
            discountStrategy = new DiscountStrategy();
        }

        /**
         * Discount percent builder.
         *
         * @param discountPercent the discount percent
         * @return the builder
         */
        public Builder discountPercent(double discountPercent) {
            this.discountPercent = discountPercent;
            return this;
        }

        /**
         * Build discount strategy.
         *
         * @return the discount strategy
         */
        public DiscountStrategy build() {
            discountStrategy.discountPercent = this.discountPercent;
            return discountStrategy;
        }
    }

}
